<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>抽奖</button>
    <script>
        // 1. 封装一个获取随机数rand函数

        // console.log(rnd(2,5));
        function rnd(n,m){
            return Math.ceil(Math.random()*(m-n+1))+n-1;
        }

        // 2. 获取按钮
        let btn = document.querySelector('button');
        // 3. 添加点击事件
        btn.onclick = function(){
            setTimeout(() => {
               let num = rnd(1,100);
               if(num<=30){
                    // 30%
                    console.log("洗衣粉一袋");
               }else{
                   // 70%
                   console.log('劳斯莱斯5元代金券一张');
               }

            }, 1000);
        }
        // 4. 设置1s单次定时器
        // 5. 调用rand()
        // 6. 判断中奖与否 - 概率30%
        // 7. 打印中奖结果
    </script>
</body>

</html>